package com.example.backend.api.controller;


import com.example.backend.api.common.Result;
import com.example.backend.api.service.impl.AbsenceServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.text.ParseException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xwyzsn
 * @since 2023-03-07
 */
@RestController
@RequestMapping("/api/absence")
@CrossOrigin(origins = "*",maxAge = 3600)
public class AbsenceController {


    @Autowired
    private AbsenceServiceImpl absenceService;

    @GetMapping("/getall")
    public Result getAll(){
        return absenceService.getAll();
    }

    @PostMapping("approve")
    public Result approve(@RequestParam("user_id") Integer id,@RequestParam("status") String status){
        return absenceService.approve(id,status);
    }

    @PostMapping("add")
    public Result add(@RequestParam("user_id") Integer id,
                      @RequestParam("dept_id") Integer dept_id,
                      @RequestParam("name") String name,
                      @RequestParam("start_time") String startTime,
                      @RequestParam("end_time") String endTime,
                      @RequestParam(value = "type" ) String type ,
                      @RequestParam(value = "reason",required = false) String reason) throws ParseException {
        return absenceService.add(id,reason,startTime,endTime,type,dept_id,name);
    }

    @GetMapping("person")
    public Result person(@RequestParam("user_id") Integer id){
        return absenceService.person(id);
    }



}
